package cn.xchats.rpc.common.core;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

import java.io.UnsupportedEncodingException;

/*
 *
 *@author teddy
 *@date 2018/6/27
 */
public class NettyDecoder {

    public static String decoderString(ChannelHandlerContext ctx, Object msg) {
        String result = "";
        ByteBuf buf = (ByteBuf) msg;
        byte[] req = new byte[buf.readableBytes()];
        buf.readBytes(req);
        try {
            result = new String(req, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        System.out.println("msg:" + result);
        return result;
    }

}
